package cs4280.ass2.util;

import org.apache.commons.lang.StringUtils;

import cs4280.ass2.entity.Member;
import cs4280.ass2.entity.User;
import cs4280.ass2.exception.ValidateException;

public class MemberUtils extends UserUtils{
	
	public static void validate(Member member) throws ValidateException {
		
		// Reuse UserUtils
		UserUtils.validate(member);
		
		// Check whether UserType is a member
		if(!isValidUserType(member)){
			throw new ValidateException("message.error.validate.member.type.notMember");
		}
		
		// Loyalty Point
		if (member.getLoyaltyPoint() < 0) {
			throw new ValidateException("message.error.validate.member.loyaltyPoint.negativeValue");
		}
	}
	
	public static boolean isValidUserType(Member member) {
		return (StringUtils.equals(member.getType(), User.USER_TYPE_MEMBER));
	}
	
	public static double loyaltyPointToCash(Member member, double loyaltyPoint) {
		return loyaltyPoint / 2D;
	}

	public static double cashToLoyaltyPoint(Member member, double cash) {
		return cash * 2D;
	}
}
